#region File information

/**
 * File: LevelDescription.cs
 * Date: 08-03-2008
 * Auth: Jan-Jaap Severs
 * 
 * Desc: Holds information about a level.
 */

#endregion

#region Using statemens

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using System.Xml.Serialization;
using System.IO;

#endregion

namespace Gremlin.Game
{
    /// <summary>
    /// Holds information about a level.
    /// </summary>
    public class LevelDescription
    {
        #region Header

        public struct VersionInfo
        {
            public float Version;

            public VersionInfo(float version)
            {
                Version = version;
            }
        }

        public VersionInfo Header;

        #endregion

        #region Mesh objects

        /// <summary>
        /// Describes what mesh to load and where to place it in the world.
        /// </summary>
        public struct MeshInfo
        {
            // The name of the mesh to load.
            public String ResourceName;

            // The position to place the mesh at.
            public Vector3 StartPosition;

            // The orientation of the mesh.
            public Quaternion StartRotation;

            /// <summary>
            /// Creates a new MeshInfo object.
            /// </summary>
            /// <param name="resourceName">The resource name of the mesh.</param>
            /// <param name="startPosition">The position of the mesh.</param>
            /// <param name="startRotation">The orientation of the mesh.</param>
            public MeshInfo(String resourceName, Vector3 startPosition, Quaternion startRotation)
            {
                ResourceName = resourceName;
                StartPosition = startPosition;
                StartRotation = startRotation;
            }
        }

        // This array actually stores the information on all the meshes in the level.
        public MeshInfo[] MeshInfos;

        #endregion

        #region Lights

        public struct LightInfo
        {
            // The type of light.
            public int Type;

            // The light's position.
            public Vector3 Position;

            // The light's direction.
            public Vector3 Direction;

            // The light's range.
            public float Range;

            /// <summary>
            /// Creates a new LightInfo object.
            /// </summary>
            /// <param name="type">The lighttype.</param>
            /// <param name="position">The position of the light.</param>
            /// <param name="direction">The direction of the light (if applicable)</param>
            /// <param name="range">The range of the light.</param>
            public LightInfo(int type, Vector3 position, Vector3 direction, float range)
            {
                Type = type;
                Position = position;
                Direction = direction;
                Range = range;
            }
        }

        // This array actually stores the information on all the lights in the level.
        public LightInfo[] LightInfos;

        #endregion

        #region Save and Load

        /// <summary>
        /// Saves the current leveldescription to file.
        /// </summary>
        /// <param name="filename">The name of the file to save to.</param>
        public void Save(string filename)
        {
            Stream stream = File.Create(filename);

            XmlSerializer serializer = new XmlSerializer(typeof(LevelDescription));
            serializer.Serialize(stream, this);
            stream.Close();
        }

        /// <summary>
        /// Loads a leveldescription from file.
        /// </summary>
        /// <param name="filename">The name of the file to load.</param>
        /// <returns>A LevelDescription object.</returns>
        public static LevelDescription Load(string filename)
        {
            Stream stream = File.OpenRead(filename);
            XmlSerializer serializer = new XmlSerializer(typeof(LevelDescription));
            return (LevelDescription)serializer.Deserialize(stream);
        }

        #endregion
    }
}
